\ExplSyntaxOn

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Custom headers and footers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bool_if:NT \l__dnd_layout_bool
  {
\RequirePackage {fancyhdr} % Adaptation of the footers

% Setup for custom footer
\pagestyle {fancy}

\cs_if_free:NF \chaptermark
  {
    \renewcommand*{\chaptermark}[1]
      {
        \markboth
          {
            \MakeUppercase
              {
                \ifnum\value{secnumdepth}>-1
                  \chaptertitlename\ \thechapter :~
                \fi
                #1
              }
          }
          {}
      }
  }

\renewcommand*{\headrulewidth}{0pt} % no rule for header
\renewcommand*{\footrulewidth}{0pt} % no rule for footer

\fancyhf {} % clear all headers and footers

% Header is used to include the page background
\fancyhead{
  \bool_if:NT \l__dnd_show_background_bool
    {
    \begin{tikzpicture}[remember~picture,overlay]
      \node[inner~sep=0pt] at (current~page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{img/paper}};
    \end{tikzpicture}
    }
}

% Left-even page footer
\fancyfoot[LE]{%
    \DndFontFooter \leftmark
    \begin{tikzpicture}[remember~picture,overlay]
      \bool_if:NT \l__dnd_show_footer_scroll_bool {
        \node[xscale=-1,inner~sep=0pt,anchor=south,nearly~opaque] at (current~page.south) {\includegraphics[width=\paperwidth,height=.6in]{img/footerscroll}};
      }
      \node[inner~sep=0pt,anchor=south,xshift=.28in,yshift=.39in] at (current~page.south~west) {\DndFontPageNumber \thepage};
    \end{tikzpicture}
  }

% Right-odd page footer
\fancyfoot[RO]{%
    \DndFontFooter \leftmark
    \begin{tikzpicture}[remember~picture,overlay]
      \bool_if:NT \l__dnd_show_footer_scroll_bool {
        \node[inner~sep=0pt,anchor=south,nearly~opaque] at (current~page.south) {\includegraphics[width=\paperwidth,height=.6in]{img/footerscroll}};
      }
      \node[inner~sep=0pt,anchor=south,xshift=-.28in,yshift=.39in] at (current~page.south~east) {\DndFontPageNumber \thepage};
    \end{tikzpicture}
  }

\fancypagestyle {plain} {}

\fancypagestyle{empty}{%
  \fancyfoot{}
}

}
